<template>
        <div class="register-info">
            <van-field style="margin-bottom: 5px" v-model="form.CompanyName" label="公司名称" required placeholder="请输入公司名称" input-align="right"/>
            <van-field style="margin-bottom: 5px" v-model="form.ChnName" label="姓名" required placeholder="请输入姓名" input-align="right"/>
            <van-field label="手机号" style="margin-bottom: 5px" v-model="form.Mobile" input-align="right" readonly />
            <!-- 输入密码 -->
            <van-field v-model="form.Password" type="password" label="密码" required placeholder="请输入密码" input-align="right"/>
            <van-field v-model="form.ConfirmPassword" type="password" label="确认密码" required placeholder="请确认密码" input-align="right"/>
            <div class="btn_submit">
                <van-button class="br-5" block type="info" @click="onSubmit">注册</van-button>
            </div>
    </div>
</template>

<script>
import { Toast, Form } from 'vant'
import { uploadAttach,PublicUpload } from "@/api/common";
import {register } from '@/api/PAPublic'
var wait = 60
export default {
  data() {
    return {
      code: '',
      qrCode:'',
      form: {
        ChnName: '',
        Mobile:'',
        CompanyName:'',
        Password:'',
        ConfirmPassword:'',
      },
    }
  },
  created() {
    this.form.CompanyCode = this.getUrlCode().CompanyCode;
    this.qrCode = this.getUrlCode().qrCode;
    this.form.Mobile = this.getUrlCode().mobile;
    if(this.$store.state.openId){
      this.form.OpenID=this.$store.state.openId;
    }
    this.$store.commit("setEnvCode", "qyb");
  },
  methods: {
    getUrlCode() { // 截取url中的code方法
      var url = window.location.href
      var theRequest = new Object()
      if (url.indexOf("?") != -1) {
          var pos = url.indexOf("?");
          var str = url.substring(pos+1,url.length);
          var strs = str.split("&")
          for(var i = 0; i < strs.length; i ++) {
              theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1])
          }
      }
      return theRequest
    },
    // 获取验证码
    _getCode() {
      if (!/^1[3-9]\d{9}$/.test(this.form.Mobile)) {
        this.$toast('请输入正确的手机号')
        return
      }
      this.time()
      // 发送请求,用post方式
      const data = {
        mobile: this.form.Mobile,
      }
     SendSms( data)
        .then((res) => {
          if (res.success) {
            console.log('获取成功')
          }
        })
        .catch((err) => {
          console.log('获取失败')
        })
    },
    // 倒计时
    time() {
      var that = this
      if (wait == 0) {
        that.code = ''
        wait = 60
      } else {
        that.code = wait + 's' + '重新发送'
        wait--
        setTimeout(function () {
          that.time()
        }, 1000)
      }
    },
    // 表单提交
    onSubmit() {
      if (!this.form.CompanyName) {
        this.$toast('请输入公司名称')
        return
      }
      if (!this.form.ChnName) {
        this.$toast('请输入姓名')
        return
      }
      if (!this.form.Password) {
        this.$toast('请输入密码')
        return
      }
      if (!this.form.ConfirmPassword) {
        this.$toast('请确认密码')
        return
      }
      if (this.form.Password !== this.form.ConfirmPassword) {
        this.$toast('两次密码输入不一致')
        return
      }
      register(this.form)
        .then((res) => {
          Toast.success('注册成功')
          setTimeout(() => {
                this.$router.push(
                    "/index?num=" + Math.ceil(Math.random() * 100000)
                );
              }, 1500);
        })
        .catch((err) => {
          console.log('失败')
        })
    },
  },
}
</script>

<style lang="less" scoped>
.register-form {
}
.phone {
	position: relative;
	.code {
		position: absolute;
		right: 20px;
		top: 20px;
		font-size: 12px;
	}
}
.register-info {
	background-color: #e8f1f8;
	padding-bottom: 20px;
}
.img-box {
  height: 50px;
  width: 50px;
  padding: 10px;
  position: absolute;
  left: 50%;
  top: 60px;
  background-color: #fff;
  border-radius: 50%;
  overflow: hidden;
}
.popup-title
{
      line-height: 35px;
    padding: 10px;
    font-size: 15px;
    padding-left: 20px;
}
</style>